const fs = require('fs');
let equipKeyStr =
    //以下是基础物品类key串
    "cap;xap;uap;skp;xkp;ukp;hlm;xlm;ulm;fhl;"
    + "xhl;uhl;ghm;xhm;uhm;crn;xrn;urn;msk;xsk;"
    + "usk;bhm;xh9;uh9;ci0;ci1;ci2;ci3;qui;xui;"
    + "uui;lea;xea;uea;hla;xla;ula;stu;xtu;utu;"
    + "rng;xng;ung;scl;xcl;ucl;chn;xhn;uhn;brs;"
    + "xrs;urs;spl;xpl;upl;plt;xlt;ult;fld;xld;"
    + "uld;gth;xth;uth;ful;xul;uul;aar;xar;uar;"
    + "ltp;xtp;utp;buc;xuc;uuc;sml;xml;uml;lrg;"
    + "xrg;urg;kit;xit;uit;tow;xow;uow;gts;xts;"
    + "uts;bsh;xsh;ush;spk;xpk;upk;lgl;xlg;ulg;"
    + "vgl;xvg;uvg;mgl;xmg;umg;tgl;xtg;utg;hgl;"
    + "xhg;uhg;lbt;xlb;ulb;vbt;xvb;uvb;mbt;xmb;"
    + "umb;tbt;xtb;utb;hbt;xhb;uhb;lbl;zlb;ulc;"
    + "vbl;zvb;uvc;mbl;zmb;umc;tbl;ztb;utc;hbl;"
    + "zhb;uhc;dr1;dr6;drb;dr2;dr7;drc;dr3;dr8;"
    + "drd;dr4;dr9;dre;dr5;dra;drf;ba1;ba6;bab;"
    + "ba2;ba7;bac;ba3;ba8;bad;ba4;ba9;bae;ba5;"
    + "baa;baf;pa1;pa6;pab;pa2;pa7;pac;pa3;pa8;"
    + "pad;pa4;pa9;pae;pa5;paa;paf;ne1;ne6;neb;"
    + "ne2;ne7;nec;ne3;ne8;ned;ne4;ne9;nee;ne5;"
    + "nea;nef;hax;9ha;7ha;axe;9ax;7ax;2ax;92a;"
    + "72a;mpi;9mp;7mp;wax;9wa;7wa;lax;9la;7la;"
    + "bax;9ba;7ba;btx;9bt;7bt;gax;9ga;7ga;gix;"
    + "9gi;7gi;clb;9cl;7cl;spc;9sp;7sp;mac;9ma;"
    + "7ma;mst;9mt;7mt;fla;9fl;7fl;whm;9wh;7wh;"
    + "mau;9m9;7m7;gma;9gm;7gm;ssd;9ss;7ss;scm;"
    + "9sm;7sm;sbr;9sb;7sb;flc;9fc;7fc;crs;9cr;"
    + "7cr;bsd;9bs;7bs;lsd;9ls;7ls;wsd;9wd;7wd;"
    + "2hs;92h;72h;clm;9cm;7cm;gis;9gs;7gs;bsw;"
    + "9b9;7b7;flb;9fb;7fb;gsd;9gd;7gd;dgr;9dg;"
    + "7dg;dir;9di;7di;kri;9kr;7kr;bld;9bl;7bl;"
    + "tkf;9tk;7tk;tax;9ta;7ta;bkf;9bk;7bk;bal;"
    + "9b8;7b8;jav;9ja;7ja;pil;9pi;7pi;ssp;9s9;"
    + "7s7;glv;9gl;7gl;tsp;9ts;7ts;spr;9sr;7sr;"
    + "tri;9tr;7tr;brn;9br;7br;spt;9st;7st;pik;"
    + "9p9;7p7;bar;9b7;7o7;vou;9vo;7vo;scy;9s8;"
    + "7s8;pax;9pa;7pa;hal;9h9;7h7;wsc;9wc;7wc;"
    + "sbw;8sb;6sb;hbw;8hb;6hb;lbw;8lb;6lb;cbw;"
    + "8cb;6cb;sbb;8s8;6s7;lbb;8l8;6l7;swb;8sw;"
    + "6sw;lwb;8lw;6lw;lxb;8lx;6lx;mxb;8mx;6mx;"
    + "hxb;8hx;6hx;rxb;8rx;6rx;sst;8ss;6ss;lst;"
    + "8ls;6ls;cst;8cs;6cs;bst;8bs;6bs;wst;8ws;"
    + "6ws;wnd;9wn;7wn;ywn;9yw;7yw;bwn;9bw;7bw;"
    + "gwn;9gw;7gw;scp;9sc;7sc;gsc;9qs;7qs;wsp;"
    + "9ws;7ws;ktr;9ar;7ar;wrb;9wb;7wb;axf;9xf;"
    + "7xf;ces;9cs;7cs;clw;9lw;7lw;btl;9tw;7tw;"
    + "skr;9qr;7qr;ob1;ob6;obb;ob2;ob7;obc;ob3;"
    + "ob8;obd;ob4;ob9;obe;ob5;oba;obf;am1;am6;"
    + "amb;am2;am7;amc;am3;am8;amd;am4;am9;ame;"
    + "am5;ama;amf;amu;rin;jew;cm1;cm2;cm3;";
//杂物类key串
let miscKeyStr =
    "gpl;opl;gpm;opm;gps;ops;tsc;isc;vps;yps;"
    + "rvs;rvl;wms;aqv;cqv;key;gcv;gfv;"
    + "gsv;gzv;gpv;gcy;gfy;gsy;gly;gpy;gcb;gfb;"
    + "gsb;glb;gpb;gcg;gfg;gsg;glg;gpg;gcr;gfr;"
    + "gsr;glr;gpr;gcw;gfw;gsw;glw;gpw;hp1;hp2;"
    + "hp3;hp4;hp5;mp1;mp2;mp3;mp4;mp5;skc;skf;"
    + "sku;skl;skz;gld;";

let equipKeys = equipKeyStr.split(";").filter(key => key);
let miscKeys = miscKeyStr.split(";").filter(key => key);
let runeKeys =[];
for (let i =1;i<=33;i++){
    runeKeys.push(`r${i}`);
}
/**
 * [修正版] 格式化一个键值数组，每隔N个元素换行，并保持正确的JSON格式和缩进。
 * @param {string[]} keysArray 要格式化的键数组
 * @param {number} itemsPerLine 每行显示的元素数量
 * @param {number} baseIndent 数组前缀的缩进空格数
 * @returns {string} 格式化后的JSON数组字符串
 */
function formatKeysArray(keysArray, itemsPerLine = 10, baseIndent = 2) {
    if (!keysArray || keysArray.length === 0) {
        return '[]';
    }
    
    const overallIndent = ' '.repeat(baseIndent);      // "  "
    const itemLineIndent = ' '.repeat(baseIndent + 2); // "    "

    let result = '[\n';
    result += itemLineIndent; // 为第一行元素添加初始缩进

    for (let i = 0; i < keysArray.length; i++) {
        result += `"${keysArray[i]}"`;

        if (i < keysArray.length - 1) { // 如果不是最后一个元素
            result += ',';
            if ((i + 1) % itemsPerLine === 0) {
                // 每行达到10个元素后，换行并为下一行添加缩进
                result += '\n' + itemLineIndent;
            } else {
                // 同一行内的元素之间用空格分隔
                result += ' ';
            }
        }
    }

    result += `\n${overallIndent}]`; // 数组结束，并正确缩进
    return result;
}

// 构建最终的JSON对象字符串
const finalJsonString = `{\n`
    + `  "equipKeys": ${formatKeysArray(equipKeys, 10, 2)},\n`
    + `  "miscKeys": ${formatKeysArray(miscKeys, 10, 2)}\n`
    + `}`;

let fname = `exportKeys_${Date.now()}.json`;
fs.writeFileSync(fname, finalJsonString, 'utf-8');

console.log(`JSON文件已正确生成到 ${fname}`);
